<?php

namespace App\Services;
use App\Models\AgentPrice;
use Illuminate\Support\Facades\Cache;

class AgentPriceService
{
    /**
     * 获取指定代理设置的价格
     *
     * @param [type] $agent_id
     * @return void
     */
    public static function getAgentPrice($agent_id){
        $agent_price = Cache::remember("video_price_conf:agent_{$agent_id}",36000,  function ()use($agent_id) {
            $price = AgentPrice::where('agent_id',$agent_id)->select('id','agent_id','min_price','max_price')->first();
            if($price){
                $price = $price->ToArray();
            }
            if(count($price)<=0){
                $conf = ConfigService::videoPriceConfig();
                $price = AgentPrice::create([
                    'agent_id'=>$agent_id,
                    'min_price'=>$conf['content']['min_price']??1,
                    'max_price'=>$conf['content']['max_price']??1,
                ]);
            }
            return $price;
        });
        return $agent_price;
    }
}